Total Complexity | 4 |
Total Lines | 29 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | import fs from 'fs-extra'; |
||
5 | export default class TemplateReporter extends Base { |
||
6 | constructor(file, { path, templateOpts = {} } = {}) { |
||
7 | super(file); |
||
8 | this.templatePath = path; |
||
9 | this.templateOpts = templateOpts; |
||
10 | } |
||
11 | |||
12 | _generate(groups, map) { |
||
13 | return this._template({ |
||
14 | groups, |
||
15 | actions : map, |
||
16 | options : this.templateOpts |
||
17 | }); |
||
18 | } |
||
19 | |||
20 | async _init() { |
||
21 | const templateContent = await fs.readFile(this.templatePath); |
||
22 | |||
23 | this._template = handleBars.compile(templateContent.toString(), { preventIndent: true }); |
||
24 | } |
||
25 | |||
26 | async write(actions) { |
||
27 | await this._init(); |
||
28 | const { groups, map } = this._build(actions, { groupBy: [ 'context.group', 'context.title' ] }); |
||
29 | const content = this._generate(groups, map, actions); |
||
30 | |||
31 | await fs.writeFile(this.file, content); |
||
32 | } |
||
33 | } |
||
34 |